<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>第二节：蓝图和子域名 | Flask进阶课程课件</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku.html" />
    
    
    <link rel="prev" href="../di-wu-zhang-ff1a-shi-tu-gao-ji/di-yi-jie-ff1a-lei-shi-tu.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="5.2"
        data-chapter-title="第二节：蓝图和子域名"
        data-filepath="di-wu-zhang-ff1a-shi-tu-gao-ji/di-er-jie-ff1a-lan-tu.md"
        data-basepath=".."
        data-revision="Tue Aug 14 2018 17:50:50 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="chapter1.html">
            
                
                    <a href="../chapter1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        第一章：学前准备
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="chapter1/di-yi-jie-ff1a-xu-ni-huan-jing.html">
            
                
                    <a href="../chapter1/di-yi-jie-ff1a-xu-ni-huan-jing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        第一节：虚拟环境
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="di-er-zhang-ff1a-ren-shi-web.html">
            
                
                    <a href="../di-er-zhang-ff1a-ren-shi-web.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        第二章：认识web
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url.html">
            
                
                    <a href="../di-san-zhang-ff1a-flask-ru-men-2014-2014-url.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        第三章：URL与视图
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-yi-jie-ff1a-di-yi-ge-flask-cheng-xu.html">
            
                
                    <a href="../di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-yi-jie-ff1a-di-yi-ge-flask-cheng-xu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        第一节：Flask简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-er-jie-ff1a-xiang-mu-pei-zhi.html">
            
                
                    <a href="../di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-er-jie-ff1a-xiang-mu-pei-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        第二节：项目配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-san-jie-ff1a-url-yu-shi-tu-han-shu.html">
            
                
                    <a href="../di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-san-jie-ff1a-url-yu-shi-tu-han-shu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        第三节：URL与视图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-si-jie-ff1a-guan-yu-xiang-ying.html">
            
                
                    <a href="../di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-si-jie-ff1a-guan-yu-xiang-ying.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        第四节：关于响应
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        第四章：模版
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-yi-jie-ff1a-mo-ban-jian-jie.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-yi-jie-ff1a-mo-ban-jian-jie.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        第一节：模版简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-er-jie-ff1a-jinja2-mo-ban-gai-shu.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-er-jie-ff1a-jinja2-mo-ban-gai-shu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        第二节：Jinja2模版概述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-san-jie-ff1a-jinja2-guo-lv-qi.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-san-jie-ff1a-jinja2-guo-lv-qi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        第三节：过滤器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-si-jie-ff1a-jinja2-mo-ban-kong-zhi-yu-ju.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-si-jie-ff1a-jinja2-mo-ban-kong-zhi-yu-ju.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        第四节：控制语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-wu-jie-ff1a-jinja2-mo-ban-ce-shi-qi.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-wu-jie-ff1a-jinja2-mo-ban-ce-shi-qi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        第五节：测试器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-liu-jie-ff1a-hong-he-import-yu-ju.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-liu-jie-ff1a-hong-he-import-yu-ju.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        第六节：宏和import语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-qijie-ff1a-include-he-set-yu-ju.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-qijie-ff1a-include-he-set-yu-ju.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        第七节：include和set语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-ba-jie-ff1a-mo-ban-ji-cheng.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-ba-jie-ff1a-mo-ban-ji-cheng.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.</b>
                        
                        第八节：模版继承
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-jiu-jie-ff1a-zhuan-yi.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-jiu-jie-ff1a-zhuan-yi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.</b>
                        
                        第九节：转义
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-shi-jie-ff1a-shu-ju-lei-xing-he-yun-suan-fu.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-shi-jie-ff1a-shu-ju-lei-xing-he-yun-suan-fu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.10.</b>
                        
                        第十节：数据类型和运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.11" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-shi-yi-jie-ff1a-jing-tai-wen-jian-de-pei-zhi.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-shi-yi-jie-ff1a-jing-tai-wen-jian-de-pei-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.11.</b>
                        
                        第十一节：静态文件的配置
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="di-wu-zhang-ff1a-shi-tu-gao-ji.html">
            
                
                    <a href="../di-wu-zhang-ff1a-shi-tu-gao-ji.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        第五章：视图高级
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="di-wu-zhang-ff1a-shi-tu-gao-ji/di-yi-jie-ff1a-lei-shi-tu.html">
            
                
                    <a href="../di-wu-zhang-ff1a-shi-tu-gao-ji/di-yi-jie-ff1a-lei-shi-tu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        第一节：类视图
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="5.2" data-path="di-wu-zhang-ff1a-shi-tu-gao-ji/di-er-jie-ff1a-lan-tu.html">
            
                
                    <a href="../di-wu-zhang-ff1a-shi-tu-gao-ji/di-er-jie-ff1a-lan-tu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        第二节：蓝图和子域名
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        第六章：SQLAlchemy数据库
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-yi-jie-ff1a-mysql-shu-ju-ku-de-an-zhuang.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-yi-jie-ff1a-mysql-shu-ju-ku-de-an-zhuang.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        第一节：MySQL数据库的安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-yi-jie-ff1a-sqlalchemy-jie-shao-he-ji-ben-shi-yong.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-yi-jie-ff1a-sqlalchemy-jie-shao-he-ji-ben-shi-yong.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        第二节：SQLAlchemy介绍和基本使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-san-jie-ff1a-sqlalchemy-de-orm.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-san-jie-ff1a-sqlalchemy-de-orm.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        第三节：SQLAlchemy的ORM（1）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-si-jie-ff1a-sqlalchemy-de-orm-2.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-si-jie-ff1a-sqlalchemy-de-orm-2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        第四节：SQLAlchemy的ORM（2）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-wu-jie-ff1a-sqlalchemy-de-orm-3.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-wu-jie-ff1a-sqlalchemy-de-orm-3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        第五节：SQLAlchemy的ORM（3）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-liu-jie-ff1a-sqlalchemy-de-orm-4.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-liu-jie-ff1a-sqlalchemy-de-orm-4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        第六节：SQLAlchemy的ORM（4）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-qi-jie-ff1a-sqlalchemy-de-orm-5.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-qi-jie-ff1a-sqlalchemy-de-orm-5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        第七节：SQLAlchemy的ORM（5）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-si-jie-ff1aflask-sqlalchemy.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-si-jie-ff1aflask-sqlalchemy.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        第八节：Flask-SQLAlchemy
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="di-qi-zhang-ff1a-flask-script.html">
            
                
                    <a href="../di-qi-zhang-ff1a-flask-script.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        第七章：Flask-Script
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="di-bazhang-ff1a-alembic-jiao-cheng.html">
            
                
                    <a href="../di-bazhang-ff1a-alembic-jiao-cheng.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        第八章：alembic教程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9" data-path="di-ba-zhang-ff1a-flask-migrate.html">
            
                
                    <a href="../di-ba-zhang-ff1a-flask-migrate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        第九章：Flask-Migrate
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10" data-path="di-jiu-zhang-ff1a-flask-wtf.html">
            
                
                    <a href="../di-jiu-zhang-ff1a-flask-wtf.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        第十章：Flask-WTF
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11" data-path="di-shi-yi-zhang-ff1a-cookie-he-session.html">
            
                
                    <a href="../di-shi-yi-zhang-ff1a-cookie-he-session.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        第十一章：cookie和session
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12" data-path="di-shi-zhang-ff1a-shang-xia-wen.html">
            
                
                    <a href="../di-shi-zhang-ff1a-shang-xia-wen.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.</b>
                        
                        第十二章：Flask上下文
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="13" data-path="di-shi-yi-zhang-ff1a-flask-xin-hao-ji-zhi.html">
            
                
                    <a href="../di-shi-yi-zhang-ff1a-flask-xin-hao-ji-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>13.</b>
                        
                        第十三章：Flask信号机制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="14" data-path="di-shi-si-zhang-ff1a-flask.html">
            
                
                    <a href="../di-shi-si-zhang-ff1a-flask.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.</b>
                        
                        第十四章：Flask-Restful
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="14.1" data-path="di-shi-si-zhang-ff1a-flask/di-yi-jie-ff1a-restful-api-gui-fan.html">
            
                
                    <a href="../di-shi-si-zhang-ff1a-flask/di-yi-jie-ff1a-restful-api-gui-fan.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.1.</b>
                        
                        第一节：Restful API规范
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="14.2" data-path="di-shi-si-zhang-ff1a-flask/di-er-jie-ff1a-flask-restful-cha-jian.html">
            
                
                    <a href="../di-shi-si-zhang-ff1a-flask/di-er-jie-ff1a-flask-restful-cha-jian.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.2.</b>
                        
                        第二节：Flask-Restful插件
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="15" data-path="di-shi-er-zhang-ff1a-memcached-jiao-cheng.html">
            
                
                    <a href="../di-shi-er-zhang-ff1a-memcached-jiao-cheng.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>15.</b>
                        
                        第十五章：memcached教程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="16" data-path="di-shi-sizhang-ff1a-redis-jiao-cheng.html">
            
                
                    <a href="../di-shi-sizhang-ff1a-redis-jiao-cheng.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>16.</b>
                        
                        第十六章：redis教程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="17" data-path="di-shi-liu-zhang-ff1a-csrf-gong-ji.html">
            
                
                    <a href="../di-shi-liu-zhang-ff1a-csrf-gong-ji.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>17.</b>
                        
                        第十七章：CSRF攻击
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="18" data-path="di-shi-ba-zhang-ff1a-qi-niu-yun-pei-zhi.html">
            
                
                    <a href="../di-shi-ba-zhang-ff1a-qi-niu-yun-pei-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>18.</b>
                        
                        第十八章：七牛云配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="19" data-path="di-shi-jiu-zhang-ff1a-bu-shu-flask-xiang-mu.html">
            
                
                    <a href="../di-shi-jiu-zhang-ff1a-bu-shu-flask-xiang-mu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>19.</b>
                        
                        第十九章：部署Flask项目
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >Flask进阶课程课件</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x84DD;&#x56FE;&#x548C;&#x5B50;&#x57DF;&#x540D;">&#x84DD;&#x56FE;&#x548C;&#x5B50;&#x57DF;&#x540D;</h1>
<h3 id="&#x84DD;&#x56FE;&#xFF1A;">&#x84DD;&#x56FE;&#xFF1A;</h3>
<p>&#x4E4B;&#x524D;&#x6211;&#x4EEC;&#x5199;&#x7684;<code>url</code>&#x548C;&#x89C6;&#x56FE;&#x51FD;&#x6570;&#x90FD;&#x662F;&#x5904;&#x5728;&#x540C;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#xFF0C;&#x5982;&#x679C;&#x9879;&#x76EE;&#x6BD4;&#x8F83;&#x5927;&#x7684;&#x8BDD;&#xFF0C;&#x8FD9;&#x663E;&#x7136;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;&#x5408;&#x7406;&#x7684;&#x7ED3;&#x6784;&#xFF0C;&#x800C;&#x84DD;&#x56FE;&#x53EF;&#x4EE5;&#x4F18;&#x96C5;&#x7684;&#x5E2E;&#x6211;&#x4EEC;&#x5B9E;&#x73B0;&#x8FD9;&#x79CD;&#x9700;&#x6C42;&#x3002;&#x4EE5;&#x4E0B;&#x770B;&#x4E00;&#x4E2A;&#x4F7F;&#x7528;&#x84DD;&#x56FE;&#x7684;&#x6587;&#x4EF6;&#x7684;&#x4F8B;&#x5B50;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> flask <span class="hljs-keyword">import</span> Blueprint
bp = Blueprint(<span class="hljs-string">&apos;user&apos;</span>,__name__,url_prefix=<span class="hljs-string">&apos;/user/&apos;</span>)

<span class="hljs-decorator">@bp.route(&apos;/&apos;)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">index</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&#x7528;&#x6237;&#x9996;&#x9875;&quot;</span>

<span class="hljs-decorator">@bp.route(&apos;profile/&apos;)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">profile</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&#x4E2A;&#x4EBA;&#x7B80;&#x4ECB;&quot;</span>
</code></pre>
<p>&#x7136;&#x540E;&#x6211;&#x4EEC;&#x5728;&#x4E3B;&#x7A0B;&#x5E8F;&#x4E2D;&#xFF0C;&#x901A;&#x8FC7;<code>app.register_blueprint()</code>&#x65B9;&#x6CD5;&#x5C06;&#x8FD9;&#x4E2A;&#x84DD;&#x56FE;&#x6CE8;&#x518C;&#x8FDB;url&#x6620;&#x5C04;&#x4E2D;&#xFF0C;&#x770B;&#x4E0B;&#x4E3B;<code>app</code>&#x7684;&#x5B9E;&#x73B0;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> flask <span class="hljs-keyword">import</span> Flask
<span class="hljs-keyword">import</span> user

app = Flask(__name__)
app.register_blueprint(user.bp)

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
    app.run(host=<span class="hljs-string">&apos;0.0.0.0&apos;</span>,port=<span class="hljs-number">9000</span>)
</code></pre>
<p>&#x4EE5;&#x540E;&#x8BBF;&#x95EE;<code>/user/</code>&#xFF0C;<code>/user/profile/</code>&#xFF0C;&#x90FD;&#x662F;&#x6267;&#x884C;&#x7684;<code>user.py</code>&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x89C6;&#x56FE;&#x51FD;&#x6570;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x5B9E;&#x73B0;&#x4E86;&#x9879;&#x76EE;&#x7684;&#x6A21;&#x5757;&#x5316;&#x3002;</p>
<p>&#x4EE5;&#x4E0A;&#x662F;&#x5BF9;&#x84DD;&#x56FE;&#x7684;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x4ECB;&#x7ECD;&#xFF0C;&#x4F46;&#x662F;&#x4F7F;&#x7528;&#x84DD;&#x56FE;&#x8FD8;&#x6709;&#x51E0;&#x4E2A;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x5730;&#x65B9;&#xFF0C;&#x5C31;&#x662F;&#x5728;&#x84DD;&#x56FE;&#x5982;&#x4F55;&#x5BFB;&#x627E;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x3001;&#x6A21;&#x677F;&#x6587;&#x4EF6;&#xFF0C;<code>url_for</code>&#x51FD;&#x6570;&#x5982;&#x4F55;&#x53CD;&#x8F6C;<code>url</code>&#xFF0C;&#x4EE5;&#x4E0B;&#x5206;&#x522B;&#x8FDB;&#x884C;&#x89E3;&#x91CA;&#xFF1A;</p>
<h5 id="&#x5BFB;&#x627E;&#x9759;&#x6001;&#x6587;&#x4EF6;&#xFF1A;">&#x5BFB;&#x627E;&#x9759;&#x6001;&#x6587;&#x4EF6;&#xFF1A;</h5>
<p>&#x9ED8;&#x8BA4;&#x4E0D;&#x8BBE;&#x7F6E;&#x4EFB;&#x4F55;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x8DEF;&#x5F84;&#xFF0C;<code>Jinja2</code>&#x4F1A;&#x5728;&#x9879;&#x76EE;&#x7684;<code>static</code>&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#x5BFB;&#x627E;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x3002;&#x4E5F;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x5176;&#x4ED6;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x5728;&#x521D;&#x59CB;&#x5316;&#x84DD;&#x56FE;&#x7684;&#x65F6;&#x5019;&#xFF0C;<code>Blueprint</code>&#x8FD9;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x6709;&#x4E00;&#x4E2A;&#x53C2;&#x6570;<code>static_folder</code>&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x5982;&#xFF1A;</p>
<pre><code class="lang-python">  bp = Blueprint(<span class="hljs-string">&apos;admin&apos;</span>,__name__,url_prefix=<span class="hljs-string">&apos;/admin&apos;</span>,static_folder=<span class="hljs-string">&apos;static&apos;</span>)
</code></pre>
<p>  <code>static_folder</code>&#x53EF;&#x4EE5;&#x662F;&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#xFF08;&#x76F8;&#x5BF9;&#x84DD;&#x56FE;&#x6587;&#x4EF6;&#x6240;&#x5728;&#x7684;&#x76EE;&#x5F55;&#xFF09;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;&#x3002;&#x5728;&#x914D;&#x7F6E;&#x5B8C;&#x84DD;&#x56FE;&#x540E;&#xFF0C;&#x8FD8;&#x6709;&#x4E00;&#x4E2A;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x5730;&#x65B9;&#x662F;&#x5982;&#x4F55;&#x5728;&#x6A21;&#x677F;&#x4E2D;&#x5F15;&#x7528;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x3002;&#x5728;&#x6A21;&#x677F;&#x4E2D;&#x5F15;&#x7528;&#x84DD;&#x56FE;&#xFF0C;&#x5E94;&#x8BE5;&#x8981;&#x4F7F;&#x7528;<code>&#x84DD;&#x56FE;&#x540D;+.+static</code>&#x6765;&#x5F15;&#x7528;&#xFF0C;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-title">link</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;{{ url_for(&apos;admin.static&apos;,filename=&apos;about.css&apos;) }}&quot;</span>&gt;</span>
</code></pre>
<h5 id="&#x5BFB;&#x627E;&#x6A21;&#x677F;&#x6587;&#x4EF6;&#xFF1A;">&#x5BFB;&#x627E;&#x6A21;&#x677F;&#x6587;&#x4EF6;&#xFF1A;</h5>
<p>&#x8DDF;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x4E00;&#x6837;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E0D;&#x8BBE;&#x7F6E;&#x4EFB;&#x4F55;&#x6A21;&#x677F;&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x5C06;&#x4F1A;&#x5728;&#x9879;&#x76EE;&#x7684;<code>templates</code>&#x4E2D;&#x5BFB;&#x627E;&#x6A21;&#x677F;&#x6587;&#x4EF6;&#x3002;&#x4E5F;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x5176;&#x4ED6;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x5728;&#x6784;&#x9020;&#x51FD;&#x6570;<code>Blueprint</code>&#x4E2D;&#x6709;&#x4E00;&#x4E2A;<code>template_folder</code>&#x53C2;&#x6570;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x6A21;&#x677F;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<pre><code>  bp = Blueprint(&apos;admin&apos;,__name__,url_prefix=&apos;/admin&apos;,template_folder=&apos;templates&apos;)
</code></pre><p>  &#x6A21;&#x677F;&#x6587;&#x4EF6;&#x548C;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x6709;&#x70B9;&#x533A;&#x522B;&#xFF0C;&#x4EE5;&#x4E0A;&#x4EE3;&#x7801;&#x5199;&#x5B8C;&#x4EE5;&#x540E;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x6E32;&#x67D3;&#x4E00;&#x4E2A;&#x6A21;&#x677F;<code>return render_template(&apos;admin.html&apos;)</code>&#xFF0C;<code>Flask</code>&#x9ED8;&#x8BA4;&#x4F1A;&#x53BB;&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x7684;<code>templates</code>&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#x67E5;&#x627E;<code>admin.html</code>&#x6587;&#x4EF6;&#xFF0C;&#x5982;&#x679C;&#x627E;&#x5230;&#x4E86;&#x5C31;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x627E;&#x5230;&#xFF0C;&#x624D;&#x4F1A;&#x53BB;&#x84DD;&#x56FE;&#x6587;&#x4EF6;&#x6240;&#x5728;&#x7684;&#x76EE;&#x5F55;&#x4E0B;&#x7684;<code>templates</code>&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#x5BFB;&#x627E;&#x3002;</p>
<h5 id="urlfor&#x751F;&#x6210;url&#xFF1A;">url_for&#x751F;&#x6210;<code>url</code>&#xFF1A;</h5>
<p>&#x7528;<code>url_for</code>&#x751F;&#x6210;&#x84DD;&#x56FE;&#x7684;<code>url</code>&#xFF0C;&#x4F7F;&#x7528;&#x7684;&#x683C;&#x5F0F;&#x662F;&#xFF1A;<code>&#x84DD;&#x56FE;&#x540D;&#x79F0;+.+&#x89C6;&#x56FE;&#x51FD;&#x6570;&#x540D;&#x79F0;</code>&#x3002;&#x6BD4;&#x5982;&#x8981;&#x83B7;&#x53D6;<code>admin</code>&#x8FD9;&#x4E2A;&#x84DD;&#x56FE;&#x4E0B;&#x7684;<code>index</code>&#x89C6;&#x56FE;&#x51FD;&#x6570;&#x7684;<code>url</code>&#xFF0C;&#x5E94;&#x8BE5;&#x91C7;&#x7528;&#x4EE5;&#x4E0B;&#x65B9;&#x5F0F;&#xFF1A;</p>
<pre><code>  url_for(&apos;admin.index&apos;)
</code></pre><p>  &#x5176;&#x4E2D;&#x8FD9;&#x4E2A;<strong>&#x84DD;&#x56FE;&#x540D;&#x79F0;</strong>&#x662F;&#x5728;&#x521B;&#x5EFA;&#x84DD;&#x56FE;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F20;&#x5165;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x3002;<code>bp = Blueprint(&apos;admin&apos;,__name__,url_prefix=&apos;/admin&apos;,template_folder=&apos;templates&apos;)</code></p>
<h3 id="&#x5B50;&#x57DF;&#x540D;&#xFF1A;">&#x5B50;&#x57DF;&#x540D;&#xFF1A;</h3>
<p>&#x5B50;&#x57DF;&#x540D;&#x5728;&#x8BB8;&#x591A;&#x7F51;&#x7AD9;&#x4E2D;&#x90FD;&#x7528;&#x5230;&#x4E86;&#xFF0C;&#x6BD4;&#x5982;&#x4E00;&#x4E2A;&#x7F51;&#x7AD9;&#x53EB;&#x505A;<code>xxx.com</code>&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x5B50;&#x57DF;&#x540D;<code>cms.xxx.com</code>&#x6765;&#x4F5C;&#x4E3A;<code>cms</code>&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;&#x7684;&#x7F51;&#x5740;&#xFF0C;&#x5B50;&#x57DF;&#x540D;&#x7684;&#x5B9E;&#x73B0;&#x4E00;&#x822C;&#x4E5F;&#x662F;&#x901A;&#x8FC7;&#x84DD;&#x56FE;&#x6765;&#x5B9E;&#x73B0;&#xFF0C;&#x5728;&#x4E4B;&#x524D;&#x7AE0;&#x8282;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x521B;&#x5EFA;&#x84DD;&#x56FE;&#x7684;&#x65F6;&#x5019;&#x6DFB;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;<code>url_prefix=/user</code>&#x4F5C;&#x4E3A;url&#x524D;&#x7F00;&#xFF0C;&#x90A3;&#x6837;&#x6211;&#x4EEC;&#x5C31;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>/user/</code>&#x6765;&#x8BBF;&#x95EE;<code>user</code>&#x4E0B;&#x7684;url&#x3002;&#x4F46;&#x4F7F;&#x7528;&#x5B50;&#x57DF;&#x540D;&#x5219;&#x4E0D;&#x9700;&#x8981;&#x3002;&#x53E6;&#x5916;&#xFF0C;&#x8FD8;&#x9700;&#x8981;&#x914D;&#x7F6E;<code>SERVER_NAME</code>&#xFF0C;&#x6BD4;&#x5982;<code>app.config[SERVER_NAME]=&apos;example.com:9000&apos;</code>&#x3002;&#x5E76;&#x4E14;&#x5728;&#x6CE8;&#x518C;&#x84DD;&#x56FE;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x8FD8;&#x9700;&#x8981;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;<code>subdomain</code>&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x5C31;&#x662F;&#x5B50;&#x57DF;&#x540D;&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x5148;&#x6765;&#x770B;&#x4E00;&#x4E0B;&#x84DD;&#x56FE;&#x7684;&#x5B9E;&#x73B0;(admin.py)&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> flask <span class="hljs-keyword">import</span> Blueprint
bp = Blueprint(<span class="hljs-string">&apos;admin&apos;</span>,__name__,subdomain=<span class="hljs-string">&apos;admin&apos;</span>)

<span class="hljs-decorator">@bp.route(&apos;/&apos;)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">admin</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;Admin Page&apos;</span>
</code></pre>
<p>&#x8FD9;&#x4E2A;&#x6CA1;&#x6709;&#x591A;&#x5927;&#x533A;&#x522B;&#xFF0C;&#x63A5;&#x4E0B;&#x6765;&#x770B;&#x4E3B;<code>app</code>&#x7684;&#x5B9E;&#x73B0;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> flask <span class="hljs-keyword">import</span> Flask
<span class="hljs-keyword">import</span> admin

<span class="hljs-comment"># &#x914D;&#x7F6E;`SERVER_NAME`</span>
app.config[<span class="hljs-string">&apos;SERVER_NAME&apos;</span>] = <span class="hljs-string">&apos;example.com:8000&apos;</span>
<span class="hljs-comment"># &#x6CE8;&#x518C;&#x84DD;&#x56FE;&#xFF0C;&#x6307;&#x5B9A;&#x4E86;subdomain</span>
app.register_blueprint(admin.bp)

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
    app.run(host=<span class="hljs-string">&apos;0.0.0.0&apos;</span>,port=<span class="hljs-number">8000</span>,debug=<span class="hljs-keyword">True</span>)
</code></pre>
<p>&#x5199;&#x5B8C;&#x4EE5;&#x4E0A;&#x4E24;&#x4E2A;&#x6587;&#x4EF6;&#x540E;&#xFF0C;&#x8FD8;&#x662F;&#x4E0D;&#x80FD;&#x6B63;&#x5E38;&#x7684;&#x8BBF;&#x95EE;<code>admin.example.com:8000</code>&#x8FD9;&#x4E2A;&#x5B50;&#x57DF;&#x540D;&#xFF0C;&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x6CA1;&#x6709;&#x5728;<code>host</code>&#x6587;&#x4EF6;&#x4E2D;&#x6DFB;&#x52A0;&#x57DF;&#x540D;&#x89E3;&#x6790;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x5728;&#x6700;&#x540E;&#x6DFB;&#x52A0;&#x4E00;&#x884C;<code>127.0.0.1 admin.example.com</code>&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x5230;&#x4E86;&#x3002;&#x53E6;&#x5916;&#xFF0C;&#x5B50;&#x57DF;&#x540D;&#x4E0D;&#x80FD;&#x5728;<code>127.0.0.1</code>&#x4E0A;&#x51FA;&#x73B0;&#xFF0C;&#x4E5F;&#x4E0D;&#x80FD;&#x5728;<code>localhost</code>&#x4E0A;&#x51FA;&#x73B0;&#x3002;</p>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../di-wu-zhang-ff1a-shi-tu-gao-ji/di-yi-jie-ff1a-lei-shi-tu.html" class="navigation navigation-prev " aria-label="Previous page: 第一节：类视图"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku.html" class="navigation navigation-next " aria-label="Next page: 第六章：SQLAlchemy数据库"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
